/*
  说明：
  {
    path: '/documentation',  （路径）
    component: Layout,  （不变）
    redirect: '/documentation/index',  （重定向到该路由）
    children: [{
      path: 'index', （子路由路径）
      component: _import('documentation/index'),  （引入vue组件，此处指views/documentation/index.vue）
      name: 'documentation',  （组件名）
      meta: { title: '文档',（该title决定了侧栏显示的文字 如：文档） icon: 'documentation', noCache: true }
    }]
  }
*/
import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

// Layout 组件为功能操作区域 所有操作区组件都是它的子路由
import Layout from '../views/layout/Layout'

// 默认路由 start
export const constantRouterMap = [
	/* 登录 */
  { path: '/login', component: _import('login/index'), hidden: true },	
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  
  /* 主面板（首页） */ 
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: _import('dashboard/index'),
      name: 'dashboard',
      meta: { title: '首页', icon: 'dashboard', noCache: true }
    }]
  },

  // vue-admin文档 后期删掉
  {
    path: '/documentation',
    component: Layout,
    redirect: '/documentation/index',
    children: [{
      path: 'index',
      component: _import('documentation/index'),
      name: 'documentation',
      meta: { title: '文档', icon: 'documentation', noCache: true }
    }]
  }
]
// 默认路由 end

export default new Router({
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

// 异步路由 具体根据权限在permission.js做判断    在这里加路由
export const asyncRouterMap = [
  // 权限测试页，只有admin权限才能看到该页
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/index',
    meta: { roles: ['admin'] }, // admin权限
    children: [{
      path: 'index',
      component: _import('permission/index'),
      name: 'permission',
      meta: {
        title: '权限测试',
        icon: 'lock',
        roles: ['admin'] // admin权限
      }
    }]
  },
  // 图标
  {
    path: '/icon',
    component: Layout,
    children: [{
      path: 'index',
      component: _import('svg-icons/index'),
      name: 'icons',
      meta: { title: '图标', icon: 'icon', noCache: true }
    }]
  },
  // test
  {
    path: '/test',
    component: Layout,
    children: [{
      path: 'index',
      component: _import('test/index'),
      name: 'test',
      meta: { title: 'test', icon: 'icon', noCache: true }
    }]
  },

	  /* 功能 */
		{
		    path: '/funtions',
		    component: Layout,
		    redirect: 'noredirect',
		    name: 'funtions',
		    meta: {
		      title: '功能',
		      icon: 'component'
		    },
		    children: [
		    	//营销管理
		      { path: 'market',component: _import('functions/market'),name: 'market',meta: {title: '营销管理',noCache: true}},
		      //优惠券管理
		      { path: 'coupon', component: _import('functions/coupon'), name: 'coupon', meta: { title: '优惠券管理', noCache: true }},
		      //广告位管理
		      { path: 'advertisement', component: _import('functions/advertisement'), name: 'advertisement', meta: { title: '广告位管理', noCache: true }},
		      //积分商城管理
		      { path: 'integral', component: _import('functions/integral'), name: 'integral', meta: { title: '积分商城管理', noCache: true }}
		    ]
		  },
  
		  {
		    path: '/functions',
		    component: Layout,
		    hidden: true,
		    children: [{
		      path: 'addMarket',
		      component: _import('functions/addMarket'),
		      name: 'addMarket',
		      meta: { title: '新增营销', icon: 'icon', noCache: true }
		    }]
		  },
  {
    path: '/components',
    component: Layout,
    redirect: 'noredirect',
    name: 'component-demo',
    meta: {
      title: '组件',
      icon: 'component'
    },
    children: [
      { path: 'tinymce', component: _import('components-demo/tinymce'), name: 'tinymce-demo', meta: { title: '富文本编辑器' }},
      { path: 'markdown', component: _import('components-demo/markdown'), name: 'markdown-demo', meta: { title: 'markdown' }},
      { path: 'json-editor', component: _import('components-demo/jsonEditor'), name: 'jsonEditor-demo', meta: { title: 'JSON编辑器' }},
      { path: 'dnd-list', component: _import('components-demo/dndList'), name: 'dndList-demo', meta: { title: '列表拖拽' }},
      { path: 'splitpane', component: _import('components-demo/splitpane'), name: 'splitpane-demo', meta: { title: 'splitPane' }},
      { path: 'avatar-upload', component: _import('components-demo/avatarUpload'), name: 'avatarUpload-demo', meta: { title: '头像上传' }},
      { path: 'dropzone', component: _import('components-demo/dropzone'), name: 'dropzone-demo', meta: { title: '拖拽区域' }},
      { path: 'sticky', component: _import('components-demo/sticky'), name: 'sticky-demo', meta: { title: '吸顶Header' }},
      { path: 'count-to', component: _import('components-demo/countTo'), name: 'countTo-demo', meta: { title: '计数' }},
      { path: 'mixin', component: _import('components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin' }},
      { path: 'back-to-top', component: _import('components-demo/backToTop'), name: 'backToTop-demo', meta: { title: '返回顶部' }}
    ]
  },

  {
    path: '/charts',
    component: Layout,
    redirect: 'noredirect',
    name: 'charts',
    meta: {
      title: '图表',
      icon: 'chart'
    },
    children: [
      { path: 'keyboard', component: _import('charts/keyboard'), name: 'keyboardChart', meta: { title: 'keyboardChart', noCache: true }},
      { path: 'line', component: _import('charts/line'), name: 'lineChart', meta: { title: 'lineChart', noCache: true }},
      { path: 'mixchart', component: _import('charts/mixChart'), name: 'mixChart', meta: { title: 'mixChart', noCache: true }}
    ]
  },
/* ----------------------三级菜单案例-------------------- */
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table/complex-table',
    name: 'example',
    meta: {
      title: '例子',
      icon: 'example'
    },
    children: [
      {
        path: '/example/table',
        component: _import('example/table/index'),
        redirect: '/example/table/complex-table',
        name: 'Table',
        meta: {
          title: '表格',
          icon: 'table'
        },
        children: [
          { path: 'dynamic-table', component: _import('example/table/dynamicTable/index'), name: 'dynamicTable', meta: { title: '动态Table' }},
          { path: 'drag-table', component: _import('example/table/dragTable'), name: 'dragTable', meta: { title: '拖拽表格' }},
          { path: 'inline-edit-table', component: _import('example/table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'Table内编辑' }},
          { path: 'tree-table', component: _import('example/table/treeTable/treeTable'), name: 'treeTableDemo', meta: { title: '树形表格' }},
          { path: 'custom-tree-table', component: _import('example/table/treeTable/customTreeTable'), name: 'customTreeTableDemo', meta: { title: '自定义树表' }}
        ]
      },
      { path: 'tab/index', icon: 'tab', component: _import('example/tab/index'), name: 'tab', meta: { title: 'tab' }}
    ]
  },

  {
    path: '/form',
    component: Layout,
    redirect: 'noredirect',
    name: 'form',
    meta: {
      title: '表单',
      icon: 'form'
    },
    children: [
      { path: 'create-form', component: _import('form/create'), name: 'createForm', meta: { title: '新建表单', icon: 'table' }},
      { path: 'edit-form', component: _import('form/edit'), name: 'editForm', meta: { title: '编辑表单', icon: 'table' }}
    ]
  },
  // 错误页面 404 、 401
  {
    path: '/error',
    component: Layout,
    redirect: 'noredirect',
    name: 'errorPages',
    meta: {
      title: '错误页',
      icon: '404'
    },
    children: [
      { path: '401', component: _import('errorPage/401'), name: 'page401', meta: { title: '401错误页', noCache: true }},
      { path: '404', component: _import('errorPage/404'), name: 'page404', meta: { title: '404错误页', noCache: true }}
    ]
  },
  {
    path: '/excel',
    component: Layout,
    redirect: 'noredirect',
    children: [
      { path: 'upload-excel', component: _import('excel/uploadExcel'), name: 'uploadExcel', meta: { title: '上传Excel', icon: 'excel' }}
    ]
  },
  // 修改主题
  {
    path: '/theme',
    component: Layout,
    redirect: 'noredirect',
    children: [{ path: 'index', component: _import('theme/index'), name: 'theme', meta: { title: '主题', icon: 'theme' }}]
  },

  {
    path: '/clipboard',
    component: Layout,
    redirect: 'noredirect',
    children: [{ path: 'index', component: _import('clipboard/index'), name: 'clipboardDemo', meta: { title: '剪贴板', icon: 'clipboard' }}]
  },
  { path: '*', redirect: '/404', hidden: true }
]
